package com.gshocklab.bulkposter.view.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gshocklab.bulkposter.R;
import com.gshocklab.bulkposter.data.AccountType;

/**
 * List adapter which display possible account types with icons in list
 * @author vitaly gashock
 */

public final class AccountsTypesListAdapter extends ArrayAdapter<AccountType> {
	private List<AccountType> accountTypes;
	private LayoutInflater inflater;
	
	public AccountsTypesListAdapter(Activity context, List<AccountType> accountTypes) {
		super(context, R.layout.select_account_item, accountTypes);
		
		this.accountTypes = accountTypes;
		this.inflater = context.getLayoutInflater();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ItemViewHolder itemViewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.select_account_item, parent, false);
			itemViewHolder = new ItemViewHolder();
			itemViewHolder.labelTextView = (TextView) convertView.findViewById(R.id.text_item);
			itemViewHolder.iconImage = (ImageView) convertView.findViewById(R.id.icon_item);
			convertView.setTag(itemViewHolder);
		} else {
			itemViewHolder = (ItemViewHolder) convertView.getTag();
		}

		itemViewHolder.labelTextView.setText(accountTypes.get(position).title);
		itemViewHolder.iconImage.setImageResource(accountTypes.get(position).bigIconId);

		return convertView;
	}
	
	private class ItemViewHolder {
		public TextView labelTextView;
		public ImageView iconImage;
	}
}
